<?php 
session_start();
if (isset($_POST['dt']) && isset($_POST['tiku']) && isset($_POST['fdes'])){
    $openid=$_POST['fdes'];
    $di=(int)$_POST['di'];
	$dt=trim($_POST['dt']);
    $tiku=$_POST['tiku'];
	include_once("../c/config.php");
	$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
	if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}

	if (1 == $_SESSION['cishu']){
	    $cishu=1;
	}else{
	    $cishu=2;
	}
	 
	$fileName=3;
	
	$getFile='../'.$fileName.'c.txt';
	$tiDataInfo=json_decode(file_get_contents($getFile), true); //考题答案
	$tiData=$tiDataInfo['d'];
	if (empty($tiDataInfo)){
		$tiData=array();
		$sql="select id,dan from ti ";
		$query = $mysqli->query($sql);
		while ($list=$query->fetch_array()){
			$tiData[$list['id']]=array('dan'=>$list['dan']);  
		}
		file_put_contents($getFile, json_encode(array('d'=>$tiData)));
	}else{
		$tiData=$tiDataInfo['d'];
	}
 
	$dati=json_decode($dt);
	$tikuTmp=json_decode($tiku);
	$dadui=0; //回答正确的提数
	$fenshu=0; //考生分数
	foreach ($dati as $k => $v){
	    if (!empty($v)){
	        if ($tiData[$tikuTmp[$k]]['dan'] == $v){
	            $fenshu++;
	            $dadui++;
	        }
	    }
	}
	
	$sql="select id from ci3_log4 where openid='".$openid."' and skey='".$cishu."'  limit 0, 1";
	$query=$mysqli->query($sql);
	if($query->num_rows>0){
	    $mysqli->query("update ci3_log4 set di=".$di.",fen=".$fenshu.", dati='".$dt."' where openid='".$openid."' and skey='".$cishu."'   ");
	}else{
	    $mysqli->query("insert into ci3_log4(di,fen,openid,dati,skey,createtime) values(".$di.",".$fenshu.",'".$openid."','".$dt."','".$cishu."','".date("Y-m-d H:i:s")."') ");
	}
	$mysqli->close();
}
echo json_encode(array('status'=>'ok'));

?>